package com.lr.wfxmanager.controller;

import com.lr.wfxmanager.bean.AddressListDTO;
import com.lr.wfxmanager.bean.City;
import com.lr.wfxmanager.bean.Province;
import com.lr.wfxmanager.bean.Region;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("address")
public class AddressController {
    @Resource
    private RestTemplate restTemplate;
    //加载所有省份
    @RequestMapping("province")
    @ResponseBody
    public List<Province> province(){
        AddressListDTO listDTO = restTemplate.getForObject("http://zmt-server/address/province", AddressListDTO.class);
        List<Province> provinces = listDTO.getProvinces();
        return provinces;
    }
    //加载对应的所有城市
    @RequestMapping("city")
    @ResponseBody
    public List<City> city(String provinceId){
        AddressListDTO listDTO = restTemplate.getForObject("http://zmt-server/address/city?provinceId="+provinceId, AddressListDTO.class);
        List<City> cities = listDTO.getCities();
        return cities;
    }
    //加载对应的所有城市
    @RequestMapping("area")
    @ResponseBody
    public List<Region> area(Integer cityId){
        AddressListDTO listDTO = restTemplate.getForObject("http://zmt-server/address/area?cityId="+cityId, AddressListDTO.class);
        List<Region> regions = listDTO.getRegions();
        return regions;
    }

}
